<?php

namespace App\Services;

use App\Models\HomeBanner;
use App\Models\Mini\NoticeModel;

class HomeBannerService extends BaseService
{
    /**
     * @Notes 获取轮播图
     * @return array
     * @author ypp
     * @date 2021/3/5
     * @time 9:42
     */
    public function getBannerList(): array
    {
        //获取认证用户信息
        $user_info = auth('user')->user();
        $now       = time();
        $whereRaw = 'find_in_set('.$user_info['community_id'].',community_id)';
        /*$list = HomeBanner::where(['estate_id' => $user_info['property_id'],'is_show'=>1,'status'=>1])
            ->where([['start_time', '<=', $now], ['end_time', '>=', $now]])
            ->whereRaw($whereRaw)
            ->OrWhere(function ($query) use ($user_info) {
                $query->where(['estate_id' => $user_info['property_id']])->where('end_time', 0);
            })->orderBy('create_time', 'desc')->get();*/
        $list = HomeBanner::where(['is_show'=>1,'status'=>1,'estate_id' => $user_info['property_id']])  //物业自己；录入的未删除和未禁用的状态
        ->where(function ($query) use ($now,$user_info) {
            $query->where([['start_time', '<=', $now], ['end_time', '>=', $now]])  //有效时间内
            ->OrWhere(['end_time' =>0]);  //长期的数据
        })
            ->whereRaw($whereRaw)
            ->orderBy('create_time', 'desc')->get();
        return $list ? $this->format($list) : $this->format_error('暂无banner');

    }
}
